/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufrpe.bsi.pvs.view.admin;

import br.ufrpe.bsi.pvs.model.roupa.Roupa;
import br.ufrpe.bsi.pvs.view.PvsFrame;
import br.ufrpe.bsi.pvs.view.renders.TableHeaderRenderer;

import java.awt.Color;
import java.awt.Dimension;
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;

public class TelaPesquisaRoupa extends javax.swing.JPanel {

    public static final TelaPesquisaRoupa INSTANCE = new TelaPesquisaRoupa();

    /**
     * Create the panel.
     */
    private TelaPesquisaRoupa() {
        initComponents();
        renderTable();
    }

    public void carregarTabela(List<Roupa> listaRoupa) {
		jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1,
				1, 1, 1));

		tbRoupas.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N

		String colunas[] = { "ID", "Descricao", "Tamanho", "Estilo",
				"Tipo Roupa", "Estocados", };

		Object tabela[][] = new Object[listaRoupa.size()][colunas.length];

		int i = 0;
		for (Roupa r : listaRoupa) {
			tabela[i][0] = r.getId();
			tabela[i][1] = r.getDescricao();
			tabela[i][2] = r.getTamanho().getTamanho();
			tabela[i][3] = r.getEstilo().getNomeEstilo();
			tabela[i][4] = r.getTipoRoupa().getNome();
			tabela[i][5] = r.getQuantEstoque();
			i++;
		}

		TableModel tm = new DefaultTableModel(tabela, colunas);
		tbRoupas.setModel(tm);
		{
			boolean[] canEdit = new boolean[] { false, true, true, true, true,
					true, true };

			// boolean isCellEditable(int rowIndex, int columnIndex) {
			// return canEdit[columnIndex];
			// }
		};

		jScrollPane1.setViewportView(tbRoupas);
		if (tbRoupas.getColumnModel().getColumnCount() > 0) {
			tbRoupas.getColumnModel().getColumn(0).setResizable(false);
			tbRoupas.getColumnModel().getColumn(1).setResizable(false);
			tbRoupas.getColumnModel().getColumn(2).setResizable(false);
			tbRoupas.getColumnModel().getColumn(3).setResizable(false);
			tbRoupas.getColumnModel().getColumn(4).setResizable(false);
			tbRoupas.getColumnModel().getColumn(5).setResizable(false);
		}
	}

    
    private void renderTable() {
        tbRoupas.setTableHeader(new JTableHeader(tbRoupas.getColumnModel()) {
            @Override
            public Dimension getPreferredSize() {
                Dimension d = super.getPreferredSize();
                d.height = 28;
                return d;
            }
        });
        tbRoupas.getTableHeader().setDefaultRenderer(new TableHeaderRenderer());
        tbRoupas.setRowHeight(30);
        tbRoupas.setBackground(new Color(240,240,240));
        tbRoupas.setSelectionBackground(new Color(254, 254, 254));
        tbRoupas.setShowVerticalLines(false);
                        
        jScrollPane1.setOpaque(false);
        jScrollPane1.getViewport().setBorder(null);
        jScrollPane1.getViewport().setOpaque(false);
        
        //setColumnSizes(tbRoupas);
    }
    
    private void setColumnSizes(JTable table) {
        table.getColumnModel().getColumn(0).setMaxWidth(35); // ID
//        
//        table.getColumnModel().getColumn(1).setMinWidth(105); // CPF
//        table.getColumnModel().getColumn(1).setMaxWidth(105); // CPF
//
//        table.getColumnModel().getColumn(2).setMinWidth(225); // CAR
//        table.getColumnModel().getColumn(2).setMaxWidth(225); // CAR
//
//        table.getColumnModel().getColumn(3).setMinWidth(145); // PERIOD
//        table.getColumnModel().getColumn(3).setMaxWidth(145); // PERIOD
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbBack = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbRoupas = new javax.swing.JTable();
        lbSave = new javax.swing.JLabel();
        lbRemove = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        cbTipoCorporeo = new javax.swing.JComboBox();
        cbEstilo = new javax.swing.JComboBox();
        cbGenero = new javax.swing.JComboBox();
        cbTamanho = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        lbSubmit = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setBackground(java.awt.Color.white);

        lbBack.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/back.png"))); // NOI18N
        lbBack.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbBackMouseClicked(evt);
            }
        });


        lbSave.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save.png"))); // NOI18N
        lbSave.setToolTipText("Salvar");
        lbSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbSaveMouseClicked(evt);
            }
        });

        lbRemove.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbRemove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/remove.png"))); // NOI18N
        lbRemove.setToolTipText("Remover");
        lbRemove.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbRemoveMouseClicked(evt);
            }
        });

        jPanel1.setOpaque(false);

        cbTipoCorporeo.setBackground(new java.awt.Color(245, 245, 245));
        cbTipoCorporeo.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        cbTipoCorporeo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tipo Corporeo", "Ampulheta", "Oval", "Retangulo", "Retangulo Invertido" }));

        cbEstilo.setBackground(new java.awt.Color(245, 245, 245));
        cbEstilo.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        cbEstilo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Estilo", "Fashion", "Casual", "Dia a dia" }));

        cbGenero.setBackground(new java.awt.Color(245, 245, 245));
        cbGenero.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        cbGenero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Genero", "Masculino", "Feminino" }));

        cbTamanho.setBackground(new java.awt.Color(245, 245, 245));
        cbTamanho.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        cbTamanho.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tamanho", "PP", "P", "M", "G", "GG", "XG" }));

        jLabel5.setFont(new java.awt.Font("Gabriola", 0, 36)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Campos de pesquisa");
        jLabel5.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)));

        lbSubmit.setBackground(new java.awt.Color(0, 0, 0));
        lbSubmit.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        lbSubmit.setForeground(new java.awt.Color(255, 255, 255));
        lbSubmit.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbSubmit.setText("Pesquisar");
        lbSubmit.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)));
        lbSubmit.setOpaque(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbTipoCorporeo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbEstilo, 0, 348, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbGenero, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbTamanho, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(lbSubmit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(cbTipoCorporeo, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(cbEstilo, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbGenero, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 163, Short.MAX_VALUE)
                .addComponent(lbSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel1.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        jLabel1.setText("Pesquisar Roupas");
        jLabel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 15, 5, 15));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbBack, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(lbSave, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lbRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lbRemove, lbSave});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbBack, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbSave, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbRemove, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(81, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {lbRemove, lbSave});

    }// </editor-fold>//GEN-END:initComponents

    private void lbBackMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbBackMouseClicked
        PvsFrame.INSTANCE.menu();
    }//GEN-LAST:event_lbBackMouseClicked

    private void lbSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbSaveMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_lbSaveMouseClicked

    private void lbRemoveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbRemoveMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_lbRemoveMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbEstilo;
    private javax.swing.JComboBox cbGenero;
    private javax.swing.JComboBox cbTamanho;
    private javax.swing.JComboBox cbTipoCorporeo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbBack;
    private javax.swing.JLabel lbRemove;
    private javax.swing.JLabel lbSave;
    private javax.swing.JLabel lbSubmit;
    private javax.swing.JTable tbRoupas;
    // End of variables declaration//GEN-END:variables
}
